package org.shj.sso.util;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class HttpClient {

	public static String post(String httpUrl){
		HttpURLConnection conn = null;
		InputStream is = null;
		BufferedReader reader = null;
		try{
			URL url = new URL(httpUrl);
			conn = (HttpURLConnection)url.openConnection();
			conn.setConnectTimeout(5000); // 设置 5秒超时
			conn.setReadTimeout(5000);
			conn.setRequestMethod("POST");
			conn.connect();
			
			if(conn.getResponseCode() == 200){
				is = conn.getInputStream();
				reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
				String line;
				StringBuffer sb = new StringBuffer();
				while((line = reader.readLine()) != null){
					sb.append(line);
				}
				
				System.out.println(sb.toString());
				
				return sb.toString();
			}
			
		}catch(Exception e){
			e.printStackTrace();
		}
		return "";
	}
}
